package com.tjn.map;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class MapMethods {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("one",new A("张三",18));
        map.put("two","周二");
        map.put("two","周三");
        map.put("four","周四");
        map.put(null,"周五");
        map.put("six","周六");
        map.put("seven",null);

        System.out.println(map);
        //1.put 添加
        // 2.remove根据键删除映射关系
        map.remove(null);
        System.out.println(map);
        // 3.get 根据键获取值
        System.out.println(map.get("two"));
        // 4.size 获取元素个数
        System.out.println(map.size());
        // 5.isEmpty 判断个数是否为0
        System.out.println(map.isEmpty());
        // 6.clear 清除
        //com.tjn.map.clear();
        //System.out.println(com.tjn.map);
        // 7.containsKay查找键是否存在
        System.out.println(map.containsKey("one"));
    }
}
class A{
    private String n;
    private int age;
    public A(String n, int age) {
        this.n = n;
        this.age = age;
    }
    @Override
    public String toString() {
        return "A{" +
                "n='" + n + '\'' +
                ", age=" + age +
                '}';
    }
}